﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using TalentPools.Model;

namespace TalentPools.DAL
{
   public class CustomService
    {
       public bool DeleteCustom1(int resumeId)
       {
           string sql = "delete from custom where resumeId=@resumeId";
           SqlParameter para = new SqlParameter("@resumeId", resumeId);
           return DBHelper.ExecuteNonQuery(CommandType.Text, sql, para) > 0;
       }
       public bool DeleteCustom(int customId)
       {
           string sql = "delete from custom where customId=@customdId";
           SqlParameter para = new SqlParameter("@customdId",customId);
           return DBHelper.ExecuteNonQuery(CommandType.Text, sql, para) == 1;
       }
       public List<custom> GetCustomByCustomId(int customId)
       {
           string sql = "select * from custom where customId=@customId";
           SqlParameter para = new SqlParameter("@customId", customId);
           List<custom> list = new List<custom>();
           using (SqlDataReader dr = DBHelper.ExecuteGetReader(CommandType.Text, sql, para))
           {
               while (dr.Read())
               {
                   custom custom = new custom();
                   custom.customId = Convert.ToInt32(dr["customId"]);
                   custom.tittle = dr["tittle"].ToString();
                   custom.content = dr["content"].ToString();
                   list.Add(custom);
               }
               return list;
           }
       }
       public List<custom> GetCustom(int resumeId)
       {
           string sql = "select * from custom where resumeId=@resumeId";
           SqlParameter para = new SqlParameter("@resumeId", resumeId);
           List<custom> list = new List<custom>();
           using (SqlDataReader dr=DBHelper.ExecuteGetReader(CommandType.Text,sql,para))
           {
               while (dr.Read())
               {
                   custom custom = new custom();
                   custom.customId = Convert.ToInt32(dr["customId"]);
                   custom.tittle = dr["tittle"].ToString();
                   custom.content = dr["content"].ToString();
                   custom.resumeId = Convert.ToInt32(dr["resumeId"]);
                   list.Add(custom);
               }
               return list;
           }
       }
    }
}
